/**
 * 注册页面
 */

// 校方注册
$(document).ready(function () {
    $('#register').on('click', function() {
        var account = $('#account').val();
        if (!account) {
            eui.msg('邮箱不可为空');
            return;
        }

        var password = $('#password').val();
        if (!password) {
            eui.msg('密码不能为空');
            return;
        }

        var password2 = $('#password2').val();
        if (!password2) {
            eui.msg('确认密码不能为空');
            return;
        }

        if (password != password2) {
            eui.msg('两次密码输入不一致');
            return;
        }

        var name = $('#name').val();
        if (!name) {
            eui.msg('请输入学校/社团名');
            return;
        }

        var contacts = $('#contacts').val();
        if (!contacts) {
            eui.msg('请输入责任人姓名');
            return;
        }

        $.ajax({
            url: '/user/enroll',
            data: {
                user: account,
                password: password,
                school: school,
                name: name,
                contacts: contacts
            },
            type: 'POST',
            dataType: 'json',
            success: function (obj) {
                if (obj.code === 0) {
                    eui.alert('注册成功', function () {
                        location.href = '/page/login';
                    });
                } else {
                    alert('登陆失败，' + obj.msg);
                }
            },
            error: function (XMLHttpRequest, textStatus, errorThrown) {
                alert('系统出错');
                //alert(XMLHttpRequest.status);
                //alert(XMLHttpRequest.readyState);
                //alert(textStatus);
            }
        });
    });
});

$('#go-back').on('click', function () {
    window.history.go(-1);
});